package com.xjy.web.controller.controller;

import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.enums.BusinessType;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.system.domain.bo.ReportProjLoanQueryBo;
import com.xjy.system.domain.vo.ReportProjLoanVo;
import com.xjy.system.service.IReportProjLoanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 借款情况Controller
 *
 * @author mlb
 * @date 2022-03-15
 */
@Api(value = "借款情况控制器", tags = {"借款情况管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/report_proj_loan")
public class ReportProjLoanController extends BaseController {

    private final IReportProjLoanService iReportProjLoanService;

    /**
     * 查询借款情况列表
     */
    @ApiOperation("查询借款情况列表")
    @PreAuthorize("@ss.hasPermi('system:report_proj_loan:list')")
    @GetMapping("/list")
    public TableDataInfo<ReportProjLoanVo> list(@Validated ReportProjLoanQueryBo bo) {
        return iReportProjLoanService.queryPageList(bo);
    }

    /**
     * 导出借款情况列表
     */
    @ApiOperation("导出借款情况列表")
    @PreAuthorize("@ss.hasPermi('system:report_proj_loan:export')")
    @Log(title = "借款情况", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ReportProjLoanVo> export(@Validated ReportProjLoanQueryBo bo) {
        List<ReportProjLoanVo> list = iReportProjLoanService.queryList(bo);
        ExcelUtil<ReportProjLoanVo> util = new ExcelUtil<ReportProjLoanVo>(ReportProjLoanVo.class);
        return util.exportExcel(list, "借款情况");
    }

    /**
     * 获取借款情况详细信息
     */
    @ApiOperation("获取借款情况详细信息")
    @PreAuthorize("@ss.hasPermi('system:report_proj_loan:query')")
    @GetMapping("/{projId}")
    public AjaxResult<ReportProjLoanVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("projId") Long projId) {
        return AjaxResult.success(iReportProjLoanService.queryById(projId));
    }

}
